﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Class_Entity;
using BussinessObject;
using System.Data;

public partial class WebApplication_ADAddEncapsulation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        Encapsulation en = new Encapsulation();  
        BOProducts bo = new BOProducts();       
        
        // fill information into object en

        en.Model = txtModel.Text.Trim();    
        en.Output = txtOutput.Text.Trim(); 
        en.Size = txtSize.Text.Trim();      
        en.Weight = txtWeight.Text.Trim();  
        en.Image = "~\\WebApplication\\images\\" + FileUploadImage.FileName;
        en.Dimension = txtDimen.Text.Trim();

        FileUploadImage.SaveAs(Server.MapPath("~\\WebApplication\\images\\" + FileUploadImage.FileName));

        // check if validation are true then add to database

        if (Session["a"] == null)
        {
            bo.Add_Encapsulation(en);
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Add Successfully ..." + "');window.location.href='ADEncapsulation.aspx';</script>");
           

        }

        
        
    }
    protected void btReset_Click(object sender, EventArgs e)
    {
        resetAll();
    }

    private void resetAll()
    {
        txtModel.Text = "";
        txtDimen.Text = "";
        txtOutput.Text = "";
        txtSize.Text = "";
        txtWeight.Text = "";
        
    }

    // check if model name exits or not

    protected void txtModel_TextChanged(object sender, EventArgs e)
    {
        Encapsulation en = new Encapsulation();
        BOProducts bo = new BOProducts();       
        DataSet ds = bo.Load_Encapsulation(en);
        DataTable dt = ds.Tables[0];
        Label1.Text = "";
        Session["a"] = null;
        
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (txtModel.Text.Trim() == dt.Rows[i]["Model"].ToString())
            {
                Session["a"] = 1;
                Label1.Text = "Model already exits";
            }

        }
    }
}